﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYZShell.CSHelper.Data;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SqliteHelper db = new SqliteHelper("Data Source= ./sqlite.db3");
            string sql;
            if (!File.Exists("./sqlite.db3"))
            {
                SqliteHelper.Create("./sqlite.db3");
                sql = @"CREATE TABLE [Enum_Tables] (
	[ID] integer NOT NULL PRIMARY KEY AUTOINCREMENT, 
	[Enum_ID] integer, 
	[Enum_Name] nvarchar(254), 
	[Enum_Value] nvarchar(254), 
	[Enum_Remark] nvarchar(254)
);";
                int r = db.ExecuteNonQuery(sql);
            } 
          
            /**
            sql = "INSERT INTO Enum_Tables(Enum_ID,Enum_Name,Enum_Value,Enum_Remark) VALUES(@id,@name,@value,@remark)";
            StatementParameterCollection pars = new StatementParameterCollection();
            pars.AddInParameter("@id", DbType.Int32, 1);
            pars.AddInParameter("@name", DbType.String, "name");
            pars.AddInParameter("@value", DbType.String, "value");
            pars.AddInParameter("@remark", DbType.String, "remark");
            int r1 = db.ExecuteNonQuery(sql, pars);
            //*/
            sql = "select * from Enum_Tables";
            var dt = db.GetDataTable(sql);
            var rsstr = db.VisitDataReader<List<string>>(sql, d =>
            {
                var rs = new List<string>();
                while (d.Read())
                {                   
                    rs.Add(string.Format("{0}_{1}_{2}", d.GetValue(0), d.GetValue(1), d.GetValue(2)));                   
                }
                return rs;
            });
            foreach (var item in rsstr)
            {
                Console.WriteLine(item);
            }
            Console.Read();
            
        }
    }
}
